/*
 * @Description:
 * @Version: 2.0
 * @Autor: snzo.chen
 * @Date: 2021-09-16 10:58:58
 * @LastEditors: snzo.chen
 * @LastEditTime: 2021-09-16 15:02:37
 */
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { map, Observable } from 'rxjs';
import { AnyJson } from './data-types/common.type';
import { ServicesModule } from './services.module';

@Injectable({
  providedIn: ServicesModule,
})
export class BaseService {
  constructor(private http: HttpClient) {}

  getBaseAll(params: AnyJson): Observable<AnyJson> {
    return this.http
      .get('/base/getBaseAll', { params })
      .pipe(map((res) => res as AnyJson));
  }

  insertBase(body: AnyJson): Observable<AnyJson> {
    return this.http
      .post('/base/insertBase', body)
      .pipe(map((res) => res as AnyJson));
  }

  updateBase(body: AnyJson): Observable<AnyJson> {
    return this.http
      .post('/base/updateBase', body)
      .pipe(map((res) => res as AnyJson));
  }

  deleteBase(params: AnyJson): Observable<AnyJson> {
    return this.http
      .get('/base/deleteBase', { params })
      .pipe(map((res) => res as AnyJson));
  }

  likeBase(params: AnyJson, body: AnyJson): Observable<AnyJson> {
    return this.http
      .post('/base/likeBase', body, { params })
      .pipe(map((res) => res as AnyJson));
  }
}
